<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>margin塌陷问题</title>
  <style>
    /* margin塌陷问题   第一个子元素的上margin和最后一个元素的下margin会作用于其父元素上 
      解决办法：在父元素上设置border或者padding
    */
    .outter{
      background-color: gray;
      width: 400px;
      height: 400px;
      border: 1px solid transparent;
      /* padding: 1px; */
      overflow: hidden;
    }
    #d1{
      background-color: orange;
      width: 100px;
      height: 100px;
      margin-top: 20px;
    }
    #d2{
      background-color: red;
      width: 100px;
      height: 100px;
    }
  </style>
</head>
<body>
  <div class="outter">
    <div id="d1"></div>
    <div id="d2"></div>

  </div>
  
</body>
</html>